GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Poker-Memory-Java-Class-Project/src/EqualPairLevel.java at master · isaacrivriv/Poker-Memory-Java-Class-Project

Expand file tree

/

EqualPairLevel.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
106 lines (88 loc) · 3.17 KB
/

EqualPairLevel.java

Copy path

File metadata and controls

106 lines (88 loc) · 3.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Stores currently turned cards, allows only two cards to be uncovered on each turn
* Also handles turning cards back down after a delay if cards are different
*
* @author Michael Leonhard (Original Author)
* @author Modified by Bienvenido Vélez (UPRM)
* @version Sept 2017
*/
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class EqualPairLevel extends EasyLevel {
protected EqualPairLevel(TurnsTakenCounterLabel validTurnTime, JFrame mainFrame) {
super(validTurnTime, mainFrame);
super.getTurnsTakenCounter().setDifficultyModeLabel("Medium Level");
}
@Override
protected void makeDeck() {
// Creates a deck to fill the grid. Each card appears twice in random places.
ImageIcon backIcon = this.getCardIcons()[this.getTotalCardsPerDeck()];
// make an array of card numbers: 0, 0, 1, 1, 2, 2, ..., 7, 7
// duplicate the image in as many cards as the input imageClones
int totalCardsInGrid = getRowsPerGrid() * getCardsPerRow();
int totalUniqueCards = totalCardsInGrid/2;
// Generate one distinct random card number for each unique card
int cardsToAdd[] = new int[totalCardsInGrid];
boolean cardChosen[] = new boolean[getTotalCardsPerDeck()];
int chosenCount = 0;
Random rand = new Random();
while (chosenCount < totalUniqueCards)
{
int nextCardNo = rand.nextInt(getTotalCardsPerDeck());
if (!cardChosen[nextCardNo]) {
cardChosen[nextCardNo] = true;
cardsToAdd[2*chosenCount] = nextCardNo;
cardsToAdd[2*chosenCount + 1] = nextCardNo;
chosenCount++;
}
}
// randomize the order of the cards
this.randomizeIntArray(cardsToAdd);
// make each card object and add it to the game grid
for(int i = 0; i < cardsToAdd.length; i++)
{
// number of the card, randomized
int num = cardsToAdd[i];
// make the card object and add it to the panel
String rank = cardNames[num].substring(0, 1);
String suit = cardNames[num].substring(1, 2);
this.getGrid().add( new Card(this, this.getCardIcons()[num], backIcon, num, rank, suit));
}
}
@Override
protected boolean turnUp(Card card) {
// the card may be turned
if(this.getTurnedCardsBuffer().size() < getCardsToTurnUp())
{
this.getTurnedCardsBuffer().add(card);
if(this.getTurnedCardsBuffer().size() == getCardsToTurnUp())
{
// there are two cards faced up
// record the player's turn
this.getTurnsTakenCounter().increment();
// get the other card (which was already turned up)
Card otherCard = (Card) this.getTurnedCardsBuffer().get(0);
// the cards match, so remove them from the list (they will remain face up)
if( otherCard.getNum() == card.getNum())
this.getTurnedCardsBuffer().clear();
// the cards do not match, so start the timer to turn them down
else this.getTurnDownTimer().start();
}
return true;
}
// there are already the number of EasyMode (two face up cards) in the turnedCardsBuffer
return false;
}
@Override
public String getMode() {
// TODO Auto-generated method stub
return "MediumMode";
}
@Override
protected boolean isGameOver(){
for (int i =0; i< this.getGrid().size();i++)
if(!this.getGrid().get(i).isFaceUp()) return false;
return true;
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.