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/EasyLevel.java at master · isaacrivriv/Poker-Memory-Java-Class-Project

Expand file tree

/

EasyLevel.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
103 lines (81 loc) · 2.69 KB
/

EasyLevel.java

Copy path

File metadata and controls

103 lines (81 loc) · 2.69 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
/**
* Stores currently turned cards
* also handles turning cards back down after a delay.
*
* @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 EasyLevel extends GameLevel {
protected EasyLevel(TurnsTakenCounterLabel validTurnTime, JFrame mainFrame) {
super(validTurnTime, 2, mainFrame);
this.getTurnsTakenCounter().setDifficultyModeLabel("Easy Level");
this.setCardsPerRow(4);
this.setRowsPerGrid(4);
this.setCardsToTurnUp(2);
this.setTotalUniqueCards(this.getRowsPerGrid() * this.getCardsPerRow());
}
@Override
protected void makeDeck() {
// Creates a deck to fill the 4x4 grid with all cards different from each other
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;
// 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[chosenCount] = 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) {
// Turn up any card until all are turned up
this.getMainFrame().getTurnCounterLabel().setText("5");
if(this.getTurnedCardsBuffer().size() < this.getTotalUniqueCards())
{
this.getTurnsTakenCounter().increment();
this.getTurnedCardsBuffer().add(card);
return true;
}
// All cards are turned up
return false;
}
@Override
public String getMode() {
// TODO Auto-generated method stub
return "EasyMode";
}
@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.